<template>
	<view class="content">
		<view class="login_bk" :animation="animationData">
			<view class="title">
				<view class="title_left" @click="the_login" :class="{'check':index==0}">
					登录
				</view>
				<view class="title_right" @click="the_reg" :class="{'check':index==1}">
					注册
				</view>
			</view>

			<view class="account_password" v-show="index==0">
				<view class="account">
					<view class="img_left">
						<image
							src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-shihuazhejaing/1044bba0-0a30-11eb-81ea-f115fe74321c.png"
							></image>
					</view>
					<view class="input_con">
						<input type="number" value="" placeholder="请输入手机号" placeholder-style="color:#344b7b" v-model="CAPTCH.Phone">
					</view>
					<view class="img_right">
						<image
							src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-shihuazhejaing/0e2cb110-0a30-11eb-b680-7980c8a877b8.png"
							mode="widthFix"></image>
					</view>
				</view>
				<view class="password">
					<view class="img_left">
						<image
							src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-shihuazhejaing/0f8eb210-0a30-11eb-81ea-f115fe74321c.png"
							></image>
					</view>
					<view class="input_con">
						<input type="text" value="" placeholder="请输入密码" placeholder-style="color:#344b7b" password v-model="CAPTCH.passwrod" />
					</view>
					<view class="img_right">
						<image
							src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-shihuazhejaing/0e2cb110-0a30-11eb-b680-7980c8a877b8.png"
							mode="widthFix"></image>
					</view>
				</view>
			</view>
			<view class="forget_register" v-show="index==0">
				<view class="forget">忘记密码</view>
			</view>
			<view class="btn" @click="to_index" v-show="index==0">
				登录
			</view>

			<!-- 注册 -->

			<view class="registration_data" v-show="index==1">
				<view class="reg_name">
					<view class="img_left">
						<image
							src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-shihuazhejaing/139e1fd0-0a30-11eb-81ea-f115fe74321c.png"
							></image>
					</view>
					<view class="input_con">
						<input type="text" value="" placeholder="请输入用户名" placeholder-style="color:#344b7b"
							maxlength="11" v-model="CAPTCHA.name" />
					</view>
					<view class="img_right">
						<image
							src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-shihuazhejaing/0e2cb110-0a30-11eb-b680-7980c8a877b8.png"
							mode="widthFix"></image>
					</view>
				</view>
				<view class="reg_Phone">
					<view class="img_left">
						<image
							src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-shihuazhejaing/1044bba0-0a30-11eb-81ea-f115fe74321c.png"
							></image>
					</view>
					<view class="input_con">
						<input type="number" value="" placeholder="请输入手机号" placeholder-style="color:#344b7b"
							maxlength="11" v-model="CAPTCHA.Phone" />
					</view>
					<view class="img_right">
						<image
							src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-shihuazhejaing/0e2cb110-0a30-11eb-b680-7980c8a877b8.png"
							mode="widthFix"></image>
					</view>
				</view>
				<view class="reg_password">
					<view class="img_left">
						<image
							src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-shihuazhejaing/0f8eb210-0a30-11eb-81ea-f115fe74321c.png"
							></image>
					</view>
					<view class="input_con">
						<input type="password" value="" placeholder="请输入密码" placeholder-style="color:#344b7b"
							maxlength="20" v-model="CAPTCHA.password" />
					</view>
					<view class="img_right">
						<image
							src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-shihuazhejaing/0e2cb110-0a30-11eb-b680-7980c8a877b8.png"
							mode="widthFix"></image>
					</view>
				</view>

			</view>
			<view class="btn" @click="to_reg" v-show="index==1">
				注册 
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user:{},
				animationData: {},
				index: 0,
				CAPTCH: {
					Phone:"",
					passwrod:""
				},
				CAPTCHA: {
					name:"",
					Phone: "",
					val: "",
					password: ""
				}
			}
		},

	
		onLoad() {
			// plus.navigator.setFullscreen(true);
			// plus.navigator.setStatusBarStyle("dark")
			     
		},
		onShow: function() {
			var animation = uni.createAnimation({
				duration: 1000,
				timingFunction: "ease",
			})
			this.animation = animation
			this.y()
		},

		methods: {
			y() {
				this.animation.translateY(-320).step()
				this.animationData = this.animation.export()
			},
			to_index() {
				if (this.CAPTCH.Phone.length < 11) {
					uni.showToast({
						title: '手机号长度错误',
						icon: "none",
						position: "top"
					});
				}else{
					uni.request({
						url: 'http://123.157.242.136:8087/backend/userInfo/userlist',
						
						header: {
							'content-type': 'application/json;charset=UTF-8'
						},
						method: 'GET',
						success: (res)=> {
							
							// console.log(res.data);
							if (res.data.code == 0) {
								// console.log(res);
								for(var i=0;i<res.data.data.length;i++){
									
									if(this.CAPTCH.Phone==res.data.data[i].userAccount&&this.CAPTCH.passwrod==res.data.data[i].password){
										
										getApp().globalData.myusername=res.data.data[i].nickName
										console.log(res.data.data[i].nickName)
										uni.switchTab({
											url:"../youji/youji"
										})
										
										break;
									}else
									if(this.CAPTCH.Phone==res.data.data[i].userAccount&&this.CAPTCH.passwrod!=res.data.data[i].password){
										
										uni.showToast({
											title: '密码错误',
											icon: "none",
											position: "top"
										});
									}
									if(i==res.data.data.length-1&&this.CAPTCH.Phone!=res.data.data[i].userAccount){
										
										uni.showToast({
											title: '未找到此账户，请注册',
											icon: "none",
											position: "top"
										});
									}
									
								}
								
								
							}
							
							
						}
						
					});
					
				}
				
			},
			to_reg() {
				let that = this;
				if (this.CAPTCHA.Phone.length < 11) {
					uni.showToast({
						title: '手机号长度错误',
						icon: "none",
						position: "top"
					});
				} else if (this.CAPTCHA.password.length <= 6) {
					uni.showToast({
						title: '密码过短',
						icon: "none",
						position: "top"
					});
				} else {
					console.log(this.CAPTCHA)
					uni.request({
						url: 'http://123.157.242.136:8087/backend/userInfo/insertUser',
						data: {
							nickName: this.CAPTCHA.name,
							password: this.CAPTCHA.password,
							userAccount:this.CAPTCHA.Phone
						},
						header: {
							'content-type': 'application/json;charset=UTF-8'
						},
						method: 'POST',
						success: (res)=> {
							// console.log(res.data);
							if (res.data.code == 0) {
								uni.showToast({
									title: '注册成功',
									icon: 'none'
								});
								
							}
						}
						
					});
					this.CAPTCH.Phone=this.CAPTCHA.Phone;
					this.CAPTCH.passwrod=this.CAPTCHA.password;
					this.index = 0;
				}
				
			},
			the_login() {
				this.index = 0;

			},
			the_reg() {
				this.index = 1;

			}

		}
	}
</script>

<style>
	page {
		background-image: url(http://123.157.242.136:8089/wxc/login_bg.gif);
		background-repeat: no-repeat;
		background-size: 100% 80%;
		background-attachment: fixed
	}

	.setting {
		width: 100%;

		/* 	border: 1rpx #f00 solid; */
		overflow: hidden;
	}

	.setting>image {
		width: 100%;
		position: absolute;
		top: 30rpx;
	}

	.login_bk {
		width: 750rpx;
		height: 620rpx;
		background-color: #d9dde6;
		border-top-left-radius: 66rpx;
		border-top-right-radius: 66rpx;
		position: absolute;
		bottom: -620rpx;
		display: flex;
		justify-content: center;
		position: flex;
	}

	.title {
		/* border: #344b7b solid 2px; */
		/* font-family: cocl; */
		/* background-color: #344b7b; */
		border-radius: 20rpx;
		color: #344b7b;
		font-size: 60rpx;
		position: absolute;
		top: 50rpx;
		display: flex;
		flex-direction: row;
	}

	.title_left {
		/* border: red solid 1px; */
		padding: 10rpx;
		box-sizing: border-box;
		border-radius: 20rpx;

	}

	.title_right {
		/* background-color: #344b7b;
				color: #faf9d4; */
		/* border: red solid 1px; */
		padding: 10rpx;
		box-sizing: border-box;
		border-radius: 20rpx;

	}
	.check {
		background-color: #344b7b;
		color: #faf9d4;
	}

	.account_password {
		/* border: 1rpx #007AFF solid; */
		width: 572rpx;
		height: 170rpx; 
		position: absolute;
		top: 150rpx;
	}

	.account {
		/* border:  red solid 1px; */
		width: 572rpx;
		height: 80rpx;
		/* background-color: #4CD964; */
		
		display: flex;
		justify-content: center;
		align-items: center;
		border-bottom: 6rpx #344b7b solid;
		border-radius: 3rpx;
	}

	.password {
		/* border: red solid 1px; */
		width: 572rpx;
		height: 80rpx;
		/* background-color: #4CD964; */
		display: flex;
		justify-content: center;
		align-items: center;
		border-bottom: 6rpx #344b7b solid;
		/* position: absolute; */
		/* bottom: 0; */
	}

	.img_left {
		/* border: red solid 1px; */
		width: 50rpx;
		height: 60rpx;
		/* background-color: #000000; */
		position: absolute;
		left: 0;
	}

	.img_right {
		width: 100rpx;
		position: absolute;
		right: 0;
	}

	.img_left>image,
	.img_right>image {
		width: 100%;
		height: 100%;
	}

	.forget_register {
		/* border: red solid 1px; */
		width: 750rpx;
		height: 30rpx;
		/* 	border: 1rpx #007AFF solid; */
		position: absolute;
		top: 350rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 30rpx;
		color: #344b7b;
	}

	.forget {
		width: 100%;
		text-align: center;
		/* border: red solid 1px; */
		position: absolute;
		left: 0;
	}



	.btn {
		/* border: red solid 1px; */
		width: 350rpx;
		height: 100rpx;
		border-radius: 60rpx;
		background-color: #faf9d4;
		position: absolute;
		left: 200rpx;
		top: 450rpx;
		box-shadow: rgba(80, 78, 78, 0.53) 1rpx 1rpx 14rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 70rpx;
	}



	.registration_data {
		/* border:  red solid 1px; */
		width: 572rpx;
		height: 300rpx;
		/* border: 1rpx #007AFF solid; */
		position: absolute;
		top: 150rpx;
		
	}
	.reg_name{
		/* border: blue solid 1px; */
		width: 572rpx;
		height: 80rpx;
		/* background-color: #4CD964; */
		
		display: flex;
		justify-content: center;
		align-items: center;
		border-bottom: 6rpx #344b7b solid;
		/* position: absolute; */
		border-radius: 3rpx;
	}
	.reg_Phone {
		/* border: red solid 1px; */
		width: 572rpx;
		height: 80rpx;
		
		
		/* background-color: #4CD964; */
		display: flex;
		justify-content: center;
		align-items: center;
		border-bottom: 6rpx #344b7b solid;
		/* position: absolute; */
		border-radius: 3rpx;
	}

	.reg_password {
		/* border: red solid 1px; */
		width: 572rpx;
		height: 80rpx;
		/* background-color: #4CD964; */
		display: flex;
		justify-content: center;
		align-items: center;
		border-bottom: 6rpx #344b7b solid;
		/* position: absolute; */
		/* bottom: 0; */
	}
</style>
